package com.manus;

import com.accurev.common.process.SecurityProcess;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/**
 * Say Hello!
 * @goal sayhi
 * @requiresProject false
 * @phase process-sources
 */
public class AccurevMojo extends AbstractMojo 
{

    /**
    * The stream to work on
    *
    * @parameter expression="${accurev.stream}" default-value="blank"
    *
    */
    private String stream;

    /**
     * The user to log in with
     *
     * @parameter expression="${accurev.user}" default-value="blank"
     *
     */
    private String user;

    /**
     * The password of the user
     *
     * @parameter expression="${accurev.password}" default-value="blank"
     *
     */
    private String password;

    private AccurevClient accurevClient;

    public void setAccurevClient(AccurevClient accurevClient) {
        this.accurevClient = accurevClient;
    }
 
    public void execute() throws MojoExecutionException
    {
        checkParams();
        if (accurevClient == null) {
            accurevClient = new AccurevClientImpl(user, password);
        }
//        getLog().info(stream);
        accurevClient.login();
    }

    private void checkParams() throws MojoExecutionException{
        if (user == null) {
            throw new MojoExecutionException("User cannot be blank, specify in configuration");
        }
        if (password == null) {
            throw new MojoExecutionException("Password cannot be blank, specify in configuration");
        }
        if (stream == null) {
            throw new MojoExecutionException("Stream cannot be blank, specify in configuration");
        }
    }
}
